/**
 * @author zhouheng
 * @date 2022年03月22日 17:31
 */

package com.atguigu.gulimall.cart.controller;

import com.atguigu.common.utils.R;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TestController {

    @ResponseBody
    @RequestMapping("/testSession")
    public R testSession(HttpServletRequest request, HttpSession session) {
        request.getSession().setAttribute("aaaaaa", "bbbbbbbbbbbbb");
        Map<String, Object> map = new HashMap<>();
        map.put("key1", request.getRequestedSessionId());
        map.put("key2", request.getSession().getAttribute("aaaaaa"));
        map.put("key3", session.getId());
        return R.ok().setData(map);
    }

    @ResponseBody
    @RequestMapping("/getSession")
    public R getSession(HttpServletRequest request, HttpSession session) {
        return R.ok().setData(request.getSession().getId());
    }
}
